package com.dmatek.uwb.xml.util.iparse.bean;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.dom4j.Element;

import com.dmatek.uwb.xml.util.iparse.IDomParse;
import com.dmatek.uwb.xml.util.iparse.IListParse;
/***
 * List配置解析抽象类
 * @author zhangfu
 * @data 2019年6月22日 下午3:19:12
 * @Description
 */
public abstract class BaseListParse<T, V extends List<T>> implements IListParse<T, V> {
	private IDomParse<?> iDomParse;
	public BaseListParse(IDomParse<?> iDomParse) {
		super();
		this.iDomParse = iDomParse;
	}
	public IDomParse<?> getiDomParse() {
		return iDomParse;
	}
	public void setiDomParse(IDomParse<?> iDomParse) {
		this.iDomParse = iDomParse;
	}
	@SuppressWarnings({ "unchecked"})
	@Override
	public T parse(Element element, Map<String, Object> superMap) throws Exception {
		List<T> list = new ArrayList<T>();
		List<Element> elements = element.elements("bean");
		for (Element ele : elements) {
			Object value = getiDomParse().parse(ele, superMap);
			list.add((T) value);
		}
		return (T) list;
	}
}
